﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Bll;

namespace StockServer
{
    public partial class UserGroupInfo : DevExpress.XtraEditors.XtraForm
    {

        ClientUser ugi = new ClientUser();
        public UserGroupInfo()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void UserGroupInfo_Load(object sender, EventArgs e)
       {
           this.tvrUserGuest.Nodes.Clear();
           DataTable tblBom = new DataTable();
           tblBom.Clear();
           tblBom = (ugi.getGroupInfoByID()).Tables[0];
           DataView dta = new DataView(tblBom);

           if (dta.Count > 0)
           {
               int i = 0;
               foreach (DataRowView myrow in dta)
               {
                   //System.Windows.Forms.CheckBox cb = new CheckBox();

                   string strname = myrow["group_id"].ToString().Trim() + "-" + myrow["ac_group"].ToString().Trim();
                   TreeNode tn = new TreeNode(strname);
                   this.tvrUserGuest.Nodes.Add(tn);                  
                   populateTreeViewForGoup(strname, tvrUserGuest.Nodes[i], myrow);
                   i++;
                   this.tvrUserGuest.SelectedNode = tvrUserGuest.Nodes[0];
               }
           }

        }

        public void populateTreeViewForGoup(string parentpart, TreeNode parentNode, DataRowView parentrow)
        {
            try
            {
                string strname = "";
                DataTable tempdatatable = (ugi.getDataSetGoupChild()).Tables[0];
                DataView viewbom = new DataView(tempdatatable);
                viewbom.RowFilter = "f_id = '" + parentrow["group_id"].ToString().Trim() + "'";
                foreach (DataRowView myrow in viewbom)
                {
                    strname = myrow["group_id"].ToString().Trim() + "-" + myrow["ac_group"].ToString().Trim();
                    TreeNode mynode = new TreeNode(strname);
                    parentNode.Nodes.Add(mynode);
                  
                    populateTreeViewForGoup(strname, mynode, myrow);
                }
            }
            catch (Exception ex)
            {
                ex.GetBaseException();
            }
        }

        private Point pi;

        private void tvrUserGuest_MouseDown(object sender, MouseEventArgs e)
        {

            pi = new Point(e.X, e.Y);
        }

        private void tvrUserGuest_DoubleClick(object sender, EventArgs e)
        {
            TreeNode tn = this.tvrUserGuest.GetNodeAt(pi);
            if (pi.X < tn.Bounds.Left || pi.X > tn.Bounds.Right)
            {
                return;

            }
            else
            {string nodeinfo=tvrUserGuest.SelectedNode.Text.Split('-')[0];

            if (nodeinfo == "0" || nodeinfo == "1" || nodeinfo == "2")
            {
                return;
            }

                //treeView1.SelectedNode.Parent.Text
               listBox1.Items.Add(tvrUserGuest.SelectedNode.Text);
                tvrUserGuest.Nodes.Remove(tvrUserGuest.SelectedNode);            
            }

        }

        private void btnCale_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        /// <summary>
        /// 点击确定的时候2009-11-27
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnYes_Click(object sender, EventArgs e)
        {

        } 

    }
}